﻿using apointment.Jobs;
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace apointment.JobConfig
{
    public class JobSchedulerWork
    {
        public static async void Work()
        {
            //调度器工厂
            ISchedulerFactory Work = new StdSchedulerFactory();
            //调度器
            IScheduler schedulers_work = await Work.GetScheduler();
            await schedulers_work.GetJobGroupNames();
            /*-------------计划任务代码实现------------------*/
            //创建任务
            IJobDetail job_Work = JobBuilder.Create<WorkAbnormalAppService>()
                .WithIdentity("TimeTriggerddd", "TimeGroupdd")
                .Build();
            //创建触发器 2点一分时被执行
            //ITrigger trigger9 = TriggerBuilder.Create().WithCronSchedule("0 01 02 * * ?").WithIdentity("TimeTriggerddd", "TimeGroupdd").Build();
            //每隔多久执行一次  这个是每隔多久执行一遍
            ITrigger trigger9 = TriggerBuilder.Create().WithIdentity("TimeTriggerddd", "TimeGroupdd").WithSimpleSchedule(t => t.WithIntervalInSeconds(1).RepeatForever()).Build();
            //添加任务及触发器至调度器中
            await schedulers_work.ScheduleJob(job_Work, trigger9);
            /*-------------计划任务代码实现------------------*/
            //启动
            await schedulers_work.Start();
        }
        }
}
